﻿
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using CarTrackr.Business.Services;
using CarTrackr.Controllers;
using CarTrackr.Tests.Repository;
using Microsoft.VisualStudio.TestTools.UnitTesting;
 

using CarTrackr.Business;
 


namespace CarTrackr.Tests.Controllers
{
    [TestClass]
    public class RefuellingControllerTest
    {

        [TestMethod]
        public void RemoveTest()
        {
            AppService appService = new AppService(new FakeRepository());

            Car car = appService.GetCarByLicensePlate("ENN781");

            Refuelling refuelling = appService.ListRefuellings(car.Id)[0];

            RefuellingController target = new RefuellingController(appService);

            target.Remove(refuelling.Id, "ENN781");

            List<Refuelling> list=  appService.ListRefuellings(car.Id);

            Assert.IsFalse(list.Contains(refuelling));


        }


        
        [TestMethod()]
        public void NewTest()
        {
            // Setup
            AppService appService = new AppService(new FakeRepository());


            RefuellingController controller = new RefuellingController(appService);
           
           
            // Execute
            string licensePlate = "ENN781";

            Car car = appService.GetCarByLicensePlate(licensePlate );

            List<Refuelling> originalList = appService.ListRefuellings(car.Id);

            FormCollection formCollection = new FormCollection();
            formCollection.Add("Date", DateTime.Now.ToString());
            formCollection.Add("ServiceStation", "teststation3");
            formCollection.Add("Kilometers", "300");
            formCollection.Add("Liters", "100");
            formCollection.Add("PricePerLiter", "2");
            formCollection.Add("Total", "200");
            formCollection.Add("Usage", "100");

            controller.New(licensePlate, formCollection);

            List<Refuelling>  currentList = appService.ListRefuellings(car.Id);

            Assert.AreEqual(originalList.Count + 1, currentList.Count);
            
        }



    }
}
